﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Boiling.BoilingFacade
{
    using System;
    using System.Data;
    
    using Boiling.Common.Userdata;
    using Boiling.DataAccess;
    
    /// <summary>
    ///     facade层
    ///     <remarks>
    ///         The BoilingFacade is used to provide a simplified interface into the 
    ///         member sub systems.
    ///     </remarks>
    ///     <remarks>
    ///         This class is marked as MarshalByRefObject to support remoted scenarios. 
    ///     </remarks>
    /// </summary>
    public class UserSystem : MarshalByRefObject
    {
        /// <summary>
        ///     Retrieve a member given the user's email and password.
        ///     <param name="emailAddress">User's email address.</param>
        ///     <param name="password">User's account password.</param>
        ///     <retvalue>The user or null.</retvalue>
        ///     <exception> class='System.ApplicationException'>
        ///         The emailAddress or password is blank.
        ///     </exception>
        /// </summary>
        public Userdata GetUserByEmail(String emailaddress, String password)
        {
            //
            // Check preconditions
            //判断邮箱以及密码是否为空，均不为空才能继续


            //
            // Get the customer dataSet
            //
            Userdata dataset;
            using (DataAccess.User userDataAccess = new DataAccess.User())
            {

            }


        }

        /// <summary>
        ///     Updates a new user.
        ///     <param name="customer">User's data.</param>
        ///     <retvalue>true if Update is successful: otherwise, false.</retvalue>
        ///     <exception> class='System.ApplicationException'>
        ///         The user is null.
        ///     </exception>
        /// </summary>
        public bool UpdateUser(Userdata user)
        {
            return;
        }

        /// <summary>
        ///     Creates a new user.
        ///     <remarks>Userdata is passed back as an out parameter for remoting.</remarks>
        ///     <param name="emailAddress">User's email address.</param>
        ///     <param name="password">User's account password.</param>
        ///     <param name="name">User's name.</param>
        ///     <param name="address">User's address.</param>
        ///     <param name="country">User's country.</param>
        ///     <param name="phoneNumber">User's phone number.</param>
        ///     <param name="fax">User's fax number.</param>
        ///     <param name="Userdata">Returns User's data.</param>
        ///     <retvalue>true if Create is successful: otherwise, false.</retvalue>
        /// </summary>
        public bool RegisterNewAccount(String emailAddress,
                               String password,
                               String name,
                               String address,
                               String country,
                               String phoneNumber,
                               String fax,
                               out CustomerData custData)
        {
            //
            // Create a new row
            //
            Userdata userdata = new Userdata();

            DataTable table = custData.Tables[userdata.CUSTOMERS_TABLE];
            DataRow row = table.NewRow();
            //
            // Fill input data into new row
            //
            row[userdata.EMAIL_FIELD] = emailAddress;
            row[userdata.PASSWORD_FIELD] = password;
            row[userdata.NAME_FIELD] = name;
            row[userdata.ADDRESS_FIELD] = address;
            row[userdata.COUNTRY_FIELD] = country;
            row[userdata.PHONE_FIELD] = phoneNumber;
            row[userdata.FAX_FIELD] = fax;
            //
            // Add it to the table
            //
            table.Rows.Add(row);
            //
            // Insert the customer using the business rules
            //
            return (new User()).Insert(userdata);
        }

        public bool TestAccountAvailable(Userdata user)
        {
            return;
        }

        public bool ResetPassword(String emailaddress)
        {
            return;
        }

        public bool EnforceUserDelet(Userdata user)
        {
            return;
        }
    }    //class UserSystem
}  // namespace Boiling.BoilingFacade
